package com.pearadmin.pro.modules.consult.service.impl;

import java.util.List;
import java.util.ArrayList;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pearadmin.pro.common.web.base.page.PageResponse;
import com.pearadmin.pro.common.web.base.page.Pageable;

import com.pearadmin.pro.modules.consult.domain.ConsultService;
import com.pearadmin.pro.modules.consult.param.ConsultServiceRequest;
import com.pearadmin.pro.modules.consult.repository.ConsultServiceRepository;
import com.pearadmin.pro.modules.consult.service.ConsultServiceService;
import com.pearadmin.pro.modules.project.domain.Project;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;

/**
 * 咨询服务Service业务层处理
 *
 * @author ChenJian
 * @date 2021-08-29
 */
@Service
public class ConsultServiceServiceImpl extends ServiceImpl<ConsultServiceRepository, ConsultService> implements ConsultServiceService
{
    @Resource
    private ConsultServiceRepository consultServiceRepository;

    /**
     * 查询咨询服务
     * @param request
     * @return 咨询服务 分页集合
     * */
    @Override
    public PageResponse<ConsultService> page(ConsultServiceRequest request)
    {
        LambdaQueryWrapper<ConsultService> query = new LambdaQueryWrapper<ConsultService>();
        query.eq(ObjectUtil.isNotEmpty(request.getCoverType()),ConsultService::getCoverType,request.getCoverType());
        query.like(ObjectUtil.isNotEmpty(request.getTitle()),ConsultService::getTitle,request.getTitle());
        query.eq(ObjectUtil.isNotEmpty(request.getState()),ConsultService::getState,request.getState());
        query.ge(ObjectUtil.isNotEmpty(request.getStateReleaseTime()),ConsultService::getReleaseTime,request.getStateReleaseTime());
        query.le(ObjectUtil.isNotEmpty(request.getEndReleaseTime()),ConsultService::getReleaseTime,request.getEndReleaseTime());
        return Pageable.of(request,(()->  consultServiceRepository.selectList(query)));
    }

    /**
     * 查询咨询服务
     *
     * @param id 咨询服务ID
     * @return 咨询服务
     */
    @Override
    public ConsultService selectConsultServiceById(Long id)
    {
        return consultServiceRepository.selectById(id);
    }

}
